package com.cfm880.devart;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    private static final String TAG = "MainActivity";
    private Configuration config;

    /**
     * entire lifetime and call only once
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i(TAG, "MainActivity>>>onCreate");
        Button start = (Button) findViewById(R.id.button);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                startActivity(intent);
            }
        });
    }
    /** visible lifetime and
     * The onStart() and onStop() methods can be called multiple times,
     * as the activity becomes visible and hidden to the user. **/
    @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, "MainActivity>>>onStart");
    }
    /**foreground lifetime */
    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, "MainActivity>>>onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG, "MainActivity>>>onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        config = getResources().getConfiguration();
        Log.i(TAG, "MainActivity>>>onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "MainActivity>>>onDestroy");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, "MainActivity>>>onRestart");
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Log.i(TAG, "oldConfig>>>"+config.toString()+"newConfig>>>"+newConfig.toString());
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.i(TAG, "onSaveInstanceState");
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        Log.i(TAG, "onRestoreInstanceSate");
    }
}
